using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace SpoonCore.Message.Info
{
	public class MessageInfo
	{
		private List<AbstractMessageInfo> _infoList = new List<AbstractMessageInfo>();

		public List<AbstractMessageInfo> Infos
		{
			get { return _infoList; }
		}

		public static byte[] Default
		{
			get { return new byte[] { 0, 0, 0, 0 }; }
		}

		public byte[] GetBytes()
		{
			MemoryStream stream = new MemoryStream();
			BinaryWriter bw = new BinaryWriter(stream);

			bw.Write(Infos.Count);
			foreach (AbstractMessageInfo info in Infos)
			{
				bw.Write(info.InfoId);
				bw.Write(info.GetBytes());
			}

			return stream.ToArray();
		}

		public static MessageInfo operator |(MessageInfo i1, MessageInfo i2)
		{
			MessageInfo res = new MessageInfo();
			res.Infos.AddRange(i1.Infos);
			res.Infos.AddRange(i2.Infos);
			return res;
		}

		public static MessageInfo operator |(MessageInfo i1, AbstractMessageInfo i2)
		{
			MessageInfo res = new MessageInfo();
			res.Infos.AddRange(i1.Infos);
			res.Infos.Add(i2);
			return res;
		}
	}
}
